package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class UserPage extends InternalPage{

    @FindBy(id = "email")
    public WebElement emailField;

    @FindBy(name = "submit")
    public WebElement saveButton;

    @FindBy(css = "h2")
    public WebElement title;

    @FindBy(id = "password")
    public WebElement passwordField;

    @FindBy(id = "password2")
    public WebElement password2Field;

    public UserManagementPage changePasswordTo(String password) {
        passwordField.clear();
        passwordField.sendKeys(password);
        password2Field.clear();
        password2Field.sendKeys(password);
        saveButton.click();
        return MyPageFactory.getPage(driver, UserManagementPage.class);
    }

    public boolean isOnThisPage() {
        return title.getText().contains("Edit");
    }

    @Override
    void tryToOpen() {
        MyPageFactory.getPage(driver, UserManagementPage.class).goToEditUserPage();
    }

}
